# -*- encoding:utf-8 -*-
"""
@作者：ven
@文件名：person.py
@时间：2024-03-12  10:06
@文档说明:人员管理
"""
from com.baseApi import BaseAPI
from libs.login import Login
from com.common import f
from utils.execlUtil import ExcelUtil


class Person(BaseAPI):

    def idNumberValidate(self, idNumber):
        res = self.request_send(params={'idNumber': idNumber})
        return res

    def personApproval(self, name, idNumber, phone):
        approval_payload = {"name": name,
                            "workNumber": None,
                            "idNumber": idNumber,
                            "gender": "1",
                            "phone": phone,
                            "deptId": 26,
                            "deptname": "生产服务中心",
                            "password": "123456",
                            "photo": "https://bctq.shouhux.com/bcyy/files/photo/ed7d849340644a248c4923be273df184.jpg"}
        res = self.request_send(json=approval_payload)
        return res

    def approval(self, id):
        payload = {"id": id, "result": "1", "opinion": None}
        res = self.request_send(json=payload)
        return res


if __name__ == '__main__':

    num = int(input(">>>请选择业务1:新增人员 2:小程序端人员注册3.平台端进行人员审核"))

    if num == 1:
        token = Login().login(isRoot=True)
        for i in range(322, 350):
            payload = {"leaderFlag": "FALSE",
                       "notLead": "FALSE",
                       "notGuard": "TRUE",
                       "orderNum": i,
                       "minTimes": 0,
                       "maxTimes": 99,
                       "name": f().name_female(),
                       "serialNumber": i,
                       "dutyId": 4,
                       "mainLeaderFlag": False,
                       "teamType": None,
                       "followPersonIds": "",
                       "deptId": 3,
                       "scheduleLimit": "UNLIMITE"}
            res = Person(inToken=token).add(json=payload)
            print(res.json())


    elif num == 2:

        perObj = Person()

        for i in range(1000):

            name = f().name()
            idNumber = f().ssn()
            phone = f().phone_number()

            res_validate = perObj.idNumberValidate(idNumber)
            print(res_validate.json())
            if res_validate.json()['data'] == '注册成功':
                res = perObj.personApproval(name, idNumber, phone)
                print(res.json(), name + '注册成功\n')

        # res = perObj.personApproval(name, idNumber, phone)
        # print(res.json(), name + '注册成功\n')

    elif num == 3:
        data = ExcelUtil('../data/approval.xlsx', 'Sheet1').dict_data()
        token = Login().login(isRoot=True)
        for _ in data:
            res = Person(inToken=token).approval(_)
            print(res.json())
